package com.fei.app.controller;

import com.fei.app.util.ExcelUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.io.*;
import java.util.ArrayList;

import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**数据导入数据库
 * Created by lsd on 2017-05-09.
 */
@Controller
@RequestMapping("/import")
public class DataImportController {
    @RequestMapping("imp")
    public ModelAndView bbs(){
        ModelAndView mv = new ModelAndView();
        mv.setViewName("form_file_upload");
        return mv;
    }
    @ResponseBody
    @RequestMapping("/excelXls")
    public ModelAndView dateImport(HttpServletRequest request) throws IOException {
        String path=request.getRealPath("/upload");
        System.out.println(path);
        //1. 获取表单数据流
        InputStream in =  request.getInputStream();
        //2. 转换流
        InputStreamReader inStream = new InputStreamReader(in, "UTF-8");
        //3. 缓冲流
        BufferedReader reader = new BufferedReader(inStream);
        System.out.println(reader);
        String name = "C:\\Users\\lsd\\Desktop/list.xlsx";
        ExcelUtil excelUtil = new ExcelUtil();
        ArrayList list = null;
        try {
            list = excelUtil.excel(name);
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println(list);
        ModelAndView mv = new ModelAndView();
        mv.addObject("bb",list);
        return mv;
    }
}
